// page/mine/pages/tixian/tixian.js
var app = getApp();
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    moneySumbit: {},
    moneylist: {},
    moneyMin: '',
    moneyMinA: true,
    MoneyMax: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    wx.request({
      url: app.api.TXtakeSet() + `?memberId=${wx.getStorageSync("bizUserInfo").id}`,
      method: 'POST',
      data: {},
      success: function(res) {
        console.log(res.data.data)
        if (res.data.code == 1) {
          if (res.data.state == 1) {
            that.setData({
              moneyMin: res.data.data.moneySetting,
              moneyMinA: false
            })
          } else {
            that.setData({
              moneyMin: res.data.data.moneySetting,
              moneyMax: false
            })
          }
          that.setData({
            moneylist: res.data.data
          })
        }
      }
    })
  },
  formSubmit(e) { //提交申请成为合伙人
    console.log(e.detail.value.money)
    that = this
    if (that.data.moneyMin == 1) {
      if (e.detail.value.money < that.data.moneylist.moneySetting) {
        wx.showToast({
          title: `金额不低于${that.data.moneylist.moneySetting}`,
          icon: 'success',
          duration: 2000,
          mask: false,
          width: 300,
        })
        return false;
      }
    } else if (e.detail.value.money == 0) {
      wx.showToast({
        title: '提现金额不能为0',
        icon: 'success',
        mask: false
      })
      return false;
    } else {
      wx.request({
        url: app.api.zhmoney() + `?makePayment=1&money=${e.detail.value.money}&memberId=${wx.getStorageSync("bizUserInfo").id}`,
        method: 'POST',
        data: {
          makePayment: 1, //支付方式
          money: Number(e.detail.value.money),
          memberId: wx.getStorageSync("bizUserInfo").id
        },

        success: function(res) {
          console.log(res.data.data)
          if (res.data.code == 1) {
            that.setData({
              moneySumbit: res.data.data
            })
            that.onLoad()
          } else {
            wx.showToast({
              title: res.data.message,
              icon: 'success',
              duration: 2000
            })
            return false
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})